//
//  L9DetectionModel.m
//  INMOTION
//
//  Created by cjg on 2020/3/4.
//  Copyright © 2020 Inmotion. All rights reserved.
//

#import "L9DetectionModel.h"
#import "KSLanguageManager.h"

@implementation L9DetectionModel
- (id)init {
    self = [super init];
    if (self) {
        [self setToDefault];
    }
    return self;
}

- (void)setToDefault {
    self.errorCategories = [[NSMutableArray alloc] init];
    self.errorMessage = IMTNewCarLocalizedString(@"prompt_diagnose_ok");
}

- (void)loadL9ErrorCategoryAndMessageWithData:(L9_ErrorValues)vaues {
    if (vaues.error_controller ==1) {
        [self.errorCategories addObject:@(0)];
    }else if (vaues.error_motor == 1) {
        [self.errorCategories addObject:@(1)];
    }else if (vaues.error_battery == 1) {
        [self.errorCategories addObject:@(2)];
    }else if (vaues.error_hmic_RX == 1 || vaues.error_mc_RX == 1 || vaues.error_low_heartbeat_freq == 1 || vaues.error_posture_sensor == 1) {
        [self.errorCategories addObject:@(3)];
    }else if (vaues.error_brake_handle == 1 || vaues.error_throttle_handle == 1) {
        [self.errorCategories addObject:@(4)];
    }
    self.errorMessage = [self getCarRealTimeErrorTipWithError:vaues];
}

// 获取车辆错误代码的提示语
- (NSString *)getCarRealTimeErrorTipWithError:(L9_ErrorValues)errors {
    NSString *errorStr = @"";
    BOOL isAdd = NO;
    if (errors.error_controller == 1) {
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_error_l9_controller_error")]];
        isAdd = YES;
    }
    if (errors.error_motor == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_error_l9_motor_error")]];
        isAdd = YES;
    }
    if (errors.error_battery == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_error_l9_battery_error")]];
        isAdd = YES;
    }
    if (errors.error_hmic_RX == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_error_l9_hmic_rx_error")]];
        isAdd = YES;
    }
    if (errors.error_mc_RX == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_error_l9_mc_rx_error")]];
        isAdd = YES;
    }
    if (errors.error_low_heartbeat_freq == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_error_l9_mc_heartbeat_error")]];
        isAdd = YES;
    }
    if (errors.error_posture_sensor == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_error_l9_posture_init_error")]];
        isAdd = YES;
    }
    if (isAdd) {
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"Please contact Vorcool after-sales service.")]];
    }

    if (errors.error_voltage == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_warning_l9_battery_under_voltage")]];
    }
    if (errors.error_voltage == 2){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_warning_l9_battery_over_voltage")]];
    }
    if (errors.error_brake_handle == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_error_l9_break_handle_error")]];
    }
    if (errors.error_throttle_handle == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_error_l9_acc_handle_error")]];
    }
    if (errors.error_mos_over_temp == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_warning_l9_mos_temp_error")]];
    }
    if (errors.error_motor_over_temp == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_warning_l9_motor_temp_error")]];
    }
    if (errors.error_battery_over_temp == 1){
        errorStr = [errorStr stringByAppendingString:[NSString stringWithFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_warning_l9_battery_temp_error")]];
    }
    if (errors.error_posture_fall_down == 1){
        errorStr = [errorStr stringByAppendingFormat:@"%@\n",IMTNewCarLocalizedString(@"prompt_car_warning_l9_posture_fall_down")];
    }
    
    if (errorStr.length == 0) {
        errorStr = IMTNewCarLocalizedString(@"prompt_diagnose_ok");
    }

    return errorStr;
}

@end
